import 'package:flutter/material.dart';
import 'package:chathouse/public/Config.dart';
import '../main.dart';

class ErrorPage extends StatefulWidget {
  final VoidCallback? errorRetry; //空数据事件处理
  bool isShowBackBtn;

  ErrorPage({Key? key, this.errorRetry, this.isShowBackBtn = false})
      : super(key: key);

  @override
  ErrorPageStatePage createState() => ErrorPageStatePage();
}

class ErrorPageStatePage extends State<ErrorPage> {
  @override
  Widget build(BuildContext context) {
    BuildContext context1 = navigatorKey.currentState!.overlay!.context;
    return Scaffold(
      body: Stack(
        children: [
          Container(
            color: Colors.transparent,
            constraints: BoxConstraints.expand(),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Image.asset(
                  "assets/images/public/defaultpage_nowifi.png",
                  width: 180,
                  height: 180,
                ),
                SizedBox(
                  height: 20,
                ),
                Text('無法加載 \n 請檢查網絡或稍後重試',
                    textAlign: TextAlign.center,
                    style:
                        TextStyle(color: Styles.c_666, fontSize: Styles.f14)),
                SizedBox(
                  height: 20,
                ),
                InkWell(
                  onTap: widget.errorRetry,
                  child: Container(
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(4),
                        color: Styles.mainColor),
                    width: 80,
                    height: 32,
                    alignment: Alignment.center,
                    child: Text(
                      "重新加載",
                      style: TextStyle(color: Colors.white, fontSize: 14),
                    ),
                  ),
                )
              ],
            ),
          ),
          widget.isShowBackBtn == true
              ? Positioned(
                  left: 12,
                  top: MediaQuery.of(context1).padding.bottom + 10,
                  child: IconButton(
                    icon: Image.asset(
                        "assets/images/public/icon_system_arrow_left_b.png"),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  ),
                )
              : Container(),
        ],
      ),
    );
  }
}
